import Vue from 'vue'
import VueRouter from 'vue-router'
//import Home from '../views/Home.vue'
import login from '../components/login.vue'
import index from '../components/index.vue'
import list from '../components/product/list.vue'
import add from '../components/product/add.vue'

Vue.use(VueRouter)

const routes = [

  {
    path:'/',
    redirect:'/login'
  },
  {
    path:'/login',
    name:'登录哈',
    component:login
  },
  {
    path:'/index',
    name:'index',
    component:index,
    children:[{
      path:'/list',
      name:'list',
      component:list,
    },{
      path:'/add',
      name:'add',
      component:add,
    }]

  }

  // {
  //   path: '/',
  //   name: 'Home',
  //   component: Home
  // },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{//路由守卫，相当于后端的过滤器
  if(to.path=='/login')
  return next()
  const store=window.sessionStorage.getItem('storeData')
  if(!store)
  return next('/login')
  next()


})

export default router
